import axios from 'axios'

const http = axios.create({
    baseURL: 'https://api.apiopen.top',
    timeout: 6000
})

http.interceptors.request.use(config => {
    if (localStorage.getItem('token')) {
        config.headers.token = localStorage.getItem('token')
    }
    return config
}, err => {
    Promise.reject(err)
})

http.interceptors.response.use(response => {
    if (response.data.code === 200) {
        return response.data
    }
}, err => {
    if (err.response.code === 401) {
        console.log('token失效')
    }
    return Promise.reject(err)
})

export default http
